package com.xsdl.chain.verifier;

import com.xsdl.chain.annonation.Max;

import java.lang.reflect.Field;

public class MaxVerifier implements Validator {

    @Override
    public void validate(Field field, Object value, ValidatorContext context) throws IllegalAccessException {
        Max max = field.getAnnotation(Max.class);
        if (max != null) {
            int maxValue = max.value();
            if (value instanceof Integer) {
                int v = (Integer) value;
                if (v > maxValue) {
                    context.appendErrMsg(field.getName() + "当前值为:" + v + ",大于最大值:" + maxValue);
//                    context.stop();
//                    Object bean = context.getBean();
//                    field.setInt(bean, 20);
                }
            }
        }
    }

}
